//
//  TeacherModel.m
//  huashiedu
//
//  Created by oceans on 2018/8/30.
//  Copyright © 2018年 hema. All rights reserved.
//

#import "TeacherModel.h"
#import "HttpRequest.h"

@implementation TeacherModel

- (instancetype)initWithDic:(NSDictionary *)dic {
    self = [super init];
    if (self) {
        
        __id = [[dic objectForKey:@"id"] intValue];
        _name = [dic objectForKey:@"name"];
        _gender = [[dic objectForKey:@"gender"] intValue];
        _grade = [[dic objectForKey:@"grade"] intValue];
        _avatar = [dic objectForKey:@"avatar"];
        _nation = [dic objectForKey:@"nation"];
        _birthday = [dic objectForKey:@"birthday"];
        _scopes = [dic objectForKey:@"scopes"];
        _teacherDescription = [dic objectForKey:@"description"];
        _certs = [dic objectForKey:@"certs"];
        _followed = [[dic objectForKey:@"followed"] boolValue];
    }
    return self;
}

- (void)focusTeacher:(void (^)(void))success failed:(void (^)(void))failed {
    
    __weak typeof(self) weakself = self;
    [HttpRequest postURL:kfocus paras:@{@"model": @"teacher", @"model_id": [NSNumber numberWithInt:__id]} showProgress:NO successful:^(id  _Nullable result) {
        weakself.followed = !weakself.followed;
        if (success) {
            success();
        }
    } failed:^(int code, NSString *errMsg) {
        if (failed) {
            failed();
        }
    }];
}

@end
